//
//  UIColor+ZLCategory.m
//  ZLCategory
//
//  Created by zhaozl on 2022/4/26.
//

#import "UIColor+ZLCategory.h"

@implementation UIColor (ZLCategory)

+ (UIColor *)zl_colorWithHex:(int)hex {
    return [self zl_colorWithHex:hex alpha:1.0f];
}

+ (UIColor *)zl_colorWithHex:(int)hex alpha:(CGFloat)alpha {
    return [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0 green:((float)((hex & 0xFF00) >> 8))/255.0 blue:((float)(hex & 0xFF))/255.0 alpha:alpha];
}

+ (UIColor *)zl_randomColor {
    return [self zl_randomColorWithAlpha:1];
}

+ (UIColor *)zl_randomColorWithAlpha:(CGFloat)alpha {
    static BOOL seeded = NO;
    if (!seeded) {
        seeded = YES;
        srandom(time(NULL));
    }
    
    CGFloat red = (CGFloat)random() / (CGFloat)RAND_MAX;
    CGFloat blue = (CGFloat)random() / (CGFloat)RAND_MAX;
    CGFloat green = (CGFloat)random() / (CGFloat)RAND_MAX;
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}

@end
